package com.aixin.csopservice.controller;


import com.aixin.csopservice.model.*;
import com.aixin.csopservice.service.SupplierService;
import com.aixin.csopservice.utils.Util;
import com.aixin.csopsupplier.model.SupplierDefModel;
import com.aixin.csopuser.domain.SupplierCustomerDomain;
import com.aixin.csopuser.model.ServicesHistory;
import com.aixin.csopuser.model.ServicesHistoryModel;
import com.aixin.csopuser.model.SupplierCustomerModel;
import com.aixin.csopuser.model.SystemReturn;
import com.aixin.csopuser.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/supplierInf")
@EnableAutoConfiguration
public class SupplierImplController {

    @Autowired
    SupplierService supplierService;
    @Autowired
    CustomerService customerService;

    /**
     *    获取供应商编号
     */
    @RequestMapping(value ="/getSupplierID")
    public ReturnSupplier getSupplier(@RequestBody SupplierDefModel supplierDefModel){
        return supplierService.getSupplier(supplierDefModel);
    }

    /**
     *    获取供应商服务列表
     */
    @RequestMapping(value ="/getService")
    public ReturnSupplierService getSupplierService(@RequestBody RequestService requestService){
        return supplierService.getSupplierService(requestService.getSupplierID());
    }

    /**
     *    根据供应商获取客户
     */
    @PostMapping(value ="/getCustomer")
    public ReturnCustomer getCustomer(@RequestBody RequestService requestService){
        return supplierService.getCustomer(requestService.getSupplierID());
    }


    /**
     *    获取服务流水
     */
    @RequestMapping(value ="/getServicesHistory")
    public ReturnHistory getServicesHistory(@RequestBody ServicesHistoryModel servicesHistoryModel){
        List list=customerService.getServicesHistory(servicesHistoryModel);
        ReturnHistory returnHistory=new ReturnHistory();
        returnHistory.setReturnResultFlag("SUCCESS");
        returnHistory.setRequestTime(Util.getNowDate());
        returnHistory.setReturnHistory(list);
        return returnHistory;
    }



    /**
     *    新增服务流水
     */
    @RequestMapping(value ="/saveServicesHistory")
    public ReturnChangeHistory saveServicesHistory(@RequestBody ServicesHistory servicesHistory){
        String historyNumber=  customerService.saveServicesHistory(servicesHistory);
        ReturnChangeHistory returnChangeHistory=new ReturnChangeHistory();
        if (historyNumber!=null){
            returnChangeHistory.setReturnResultFlag("SUCCESS");
            returnChangeHistory.setRequestTime(Util.getNowDate());
            returnChangeHistory.setHistoryNumber(historyNumber);
            return returnChangeHistory;
        }
        returnChangeHistory.setReturnResultFlag("FALSE");
        returnChangeHistory.setRequestTime(Util.getNowDate());
        returnChangeHistory.setHistoryNumber(historyNumber);
        return returnChangeHistory;
    }

    /**
     *    修改服务流水
     */
    @RequestMapping(value ="/updateServicesHistory")
    public ReturnChangeHistory updateServicesHistory(@RequestBody ServicesHistory servicesHistory){
        String historyNumber=  customerService.saveServicesHistory(servicesHistory);
        ReturnChangeHistory returnChangeHistory=new ReturnChangeHistory();
        if (historyNumber!=null){
            returnChangeHistory.setReturnResultFlag("SUCCESS");
            returnChangeHistory.setRequestTime(Util.getNowDate());
            returnChangeHistory.setHistoryNumber(historyNumber);
            return returnChangeHistory;
        }
        returnChangeHistory.setReturnResultFlag("FALSE");
        returnChangeHistory.setRequestTime(Util.getNowDate());
        returnChangeHistory.setHistoryNumber(historyNumber);
        return returnChangeHistory;
    }

}
